/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "OutputStream.h"
#include "../Lang/String.h"
#include "../DataStructures/ArrayList.h"

namespace Hogshead
{
	namespace Common
	{
		/**
		* StringOutputStream is an OutputStream which stores the written bytes to an ArrayList<char>
		* and provides a toString() method.  An excellent alternative to std::stringstream as it
		* doesn't leak memory in debug mode
		* @see ArrayList
		* @see String
		*/
		class StringOutputStream : public OutputStream
		{
			public:
				/*
				* Writes a single character to the ArrayList
				* @param in_char The character to write.
				*/
				void write(char in_char);
				/*
				* Write a NULL terminated character array to the ArrayList.
				* Note you can pass String objects to this method since they
				* will autmoatically cast to a const char*.
				* @param in_string The NULL teriminated character array to write.
				*/
				void write(const char* in_string);
				/*
				* Writes a specified number of bytes to the ArrayList.
				* @param in_bytes The data buffer to read from to write.
				* @param in_count The number of bytes to write.
				*/
				void write(const char* in_bytes, unsigned int in_count);
				/*
				* Empties the buffer via the clear() method on ArrayList.
				*/
				void reset();

				/*
				* Return a pointer to a new String made up of the characters in the buffer.  NOTE: 
				* This returns a NEW String which must be deleted after use.
				*/
				String* toString();
		private:
				ArrayList<char> _buffer;
		};
	}
}